package com.hzhr.iot.meterplan.controller;

import com.hzhr.iot.core.annotation.ApiImplicitInternalParams;
import com.hzhr.iot.core.annotation.Author;
import com.hzhr.iot.core.dto.ResponseExceptionDto;
import com.hzhr.iot.core.exception.ServiceException;
import com.hzhr.iot.meterplan.controller.base.BaseController;
import com.hzhr.iot.meterplan.model.meterPlan_publish.MeterPlan_PublishGetModel;
import com.hzhr.iot.meterplan.model.meterPlan_publish.MeterPlan_PublishModel;
import com.hzhr.iot.meterplan.model.meterPlan_publish.MeterPlan_PublishPostModel;
import com.hzhr.iot.meterplan.service.MeterPlan_PublishService;
import io.swagger.annotations.*;
import org.springframework.beans.factory.annotation.Autowired;
import org.springframework.http.HttpStatus;
import org.springframework.http.ResponseEntity;
import org.springframework.web.bind.annotation.*;
import springfox.documentation.annotations.ApiIgnore;

import java.util.Map;

@Api(tags = "MeterPlan_Publish", description = "抄表计划下的发布")
@RestController
@RequestMapping(value = "")
public class MeterPlan_PublishController extends BaseController {


    @Autowired
    MeterPlan_PublishService meterPlan_publishService;

    //region /meter-plans/{meterPlanId}/meter-gas-users POST
    //region swagger响应码 : post
    @ApiResponses({
            @ApiResponse(code = 200, message = "成功"),
            @ApiResponse(code = 403, message = "----异常代码 : 201  \n----异常类型 : 业务流程异常  \n----异常业务 : 查询抄表计划状态  \n----异常说明 : 抄表计划不存在  \n\n----异常代码 : 201  \n----异常类型 : 业务流程异常  \n----异常业务 : 验证抄表计划下的抄表册  \n----异常说明 : 抄表册已经完成录入，无法发布数据  \n\n", response = ResponseExceptionDto.class),
    })
    //endregion
    //region swagger说明 : post
    @ApiOperation(value="发布", notes="发布  \n1.查询抄表计划：  \n 如果抄表计划不存在，抛出异常“抄表计划不存在”；  \n2.验证抄表计划下的抄表册：  \n 如果该抄表计划下不存在状态为“待抄表”或“待复抄”的抄表册，抛出异常“抄表册已经完成录入，无法发布数据”  \n3.发布数据：  \n 根据WorkOrder.id找到该抄表计划下的状态为“待抄表”或“待审核”的抄表工单，如果抄表工单存在，则根据WorkOrder.collectData发布数据，  \n 注意：如果本次表底数大于或等于上次表底数，则发布数据，否则不发布。  \n4.返回信息；  \n",produces = "application/json")
    //endregion
    //region swagger参数 : post
    @ApiImplicitParams({
            @ApiImplicitParam(name = "token", value = "令牌",required = true, dataType = "string", paramType = "header"),

            @ApiImplicitParam(name = "meterPlanId", value = "抄表计划id",required = true, dataType = "string", paramType = "path"),

            @ApiImplicitParam(name = "show", value = "展示形式 one:展示一个,list:展示列表,null(空值):不展示", required = false, dataType = "string", paramType = "query"),
            @ApiImplicitParam(name = "show_info", value = "是否展示详情", defaultValue = "false", required = false, dataType = "boolean", paramType = "query"),

    })
    @ApiImplicitInternalParams({
            @ApiImplicitParam(name = "_token", value = "令牌",required = true, dataType = "string", paramType = "header"),
            @ApiImplicitParam(name = "_hzhr-user-id", value = "用户编号",required = true, dataType = "int", paramType = "header"),
            @ApiImplicitParam(name = "_hzhr-user-code", value = "用户代码",required = true, dataType = "string", paramType = "header"),
            @ApiImplicitParam(name = "_hzhr-user-name", value = "用户名",required = true, dataType = "string", paramType = "header"),
            @ApiImplicitParam(name = "_hzhr-company-id", value = "公司编号",required = true, dataType = "int", paramType = "header"),
            @ApiImplicitParam(name = "_hzhr-dept-id", value = "部门编号",required = true, dataType = "int", paramType = "header"),
            @ApiImplicitParam(name = "_hzhr-user-type", value = "用户类型(关联: common_service.options.code, typeCode = 'USER_TYPE')",required = true, dataType = "string", paramType = "header"),
            @ApiImplicitParam(name = "_hzhr-transaction-id", value = "交易流水号",required = true, dataType = "string", paramType = "header"),
            @ApiImplicitParam(name = "_hzhr-transaction-type", value = "交易类型",required = true, dataType = "string", paramType = "header"),
            @ApiImplicitParam(name = "_hzhr-access-mode", value = "访问模式 0:一般 1:全局",defaultValue = "0", required = false, dataType = "int", paramType = "header"),

            @ApiImplicitParam(name = "_show", value = "展示形式 one:展示一个,list:展示列表,null(空值):不展示", required = false, dataType = "string", paramType = "query"),
            @ApiImplicitParam(name = "_show_info", value = "是否展示详情", defaultValue = "false", required = false, dataType = "boolean", paramType = "query"),

    })
    //endregion
    //region 请求 : post
    @RequestMapping(value = "/meter-plans/{meterPlanId}/publish", method = RequestMethod.POST)
    //endregion
    @Author
    public ResponseEntity<MeterPlan_PublishGetModel> post(@PathVariable("meterPlanId") String meterPlanId,
                                                          @RequestParam @ApiIgnore Map<String, Object> query,
                                                          @RequestBody MeterPlan_PublishPostModel body) throws ServiceException {
        MeterPlan_PublishGetModel responseBody = meterPlan_publishService.post(initHeader(),meterPlanId,query,body);
        return new ResponseEntity<>(responseBody, HttpStatus.OK);
    }
    //endregion
}




